package icu.qx.pbs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import icu.qx.pbs.domain.PbsWorkCell;
import icu.qx.pbs.service.IPbsWorkCellService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;

/**
 * 生产单元Controller
 *
 * @author yong
 * @date 2024-06-18
 */
@RestController
@RequestMapping("/pbs/workCell")
public class PbsWorkCellController extends BaseController {
    @Autowired
    private IPbsWorkCellService pbsWorkCellService;

    /**
     * 查询生产单元列表
     */
    @RequiresPermissions("pbs:workCell:list")
    @GetMapping("/list")
    public AjaxResult list(PbsWorkCell pbsWorkCell) {
        List<PbsWorkCell> list = pbsWorkCellService.selectPbsWorkCellList(pbsWorkCell);
        return success(list);
    }

    /**
     * 导出生产单元列表
     */
    @RequiresPermissions("pbs:workCell:export")
    @Log(title = "生产单元", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PbsWorkCell pbsWorkCell) {
        List<PbsWorkCell> list = pbsWorkCellService.selectPbsWorkCellList(pbsWorkCell);
        ExcelUtil<PbsWorkCell> util = new ExcelUtil<PbsWorkCell>(PbsWorkCell.class);
        util.exportExcel(response, list, "生产单元数据");
    }

    /**
     * 获取生产单元详细信息
     */
    @RequiresPermissions("pbs:workCell:query")
    @GetMapping(value = "/{workCellCode}")
    public AjaxResult getInfo(@PathVariable("workCellCode") String workCellCode) {
        return success(pbsWorkCellService.selectPbsWorkCellByWorkCellCode(workCellCode));
    }

    @RequiresPermissions("pbs:workCell:query")
    @GetMapping(value = "fid/{workCellFid}")
    public AjaxResult getInfoByFid(@PathVariable("workCellFid") String workCellFid) {
        return success(pbsWorkCellService.selectPbsWorkCellByFid(workCellFid));
    }

    /**
     * 新增生产单元
     */
    @RequiresPermissions("pbs:workCell:add")
    @Log(title = "生产单元", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PbsWorkCell pbsWorkCell) {
        return toAjax(pbsWorkCellService.insertPbsWorkCell(pbsWorkCell));
    }

    /**
     * 修改生产单元
     */
    @RequiresPermissions("pbs:workCell:edit")
    @Log(title = "生产单元", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PbsWorkCell pbsWorkCell) {
        return toAjax(pbsWorkCellService.updatePbsWorkCell(pbsWorkCell));
    }

    /**
     * 删除生产单元
     */
    @RequiresPermissions("pbs:workCell:remove")
    @Log(title = "生产单元", businessType = BusinessType.DELETE)
    @DeleteMapping("/{workCellCodes}")
    public AjaxResult remove(@PathVariable String[] workCellCodes) {
        return toAjax(pbsWorkCellService.deletePbsWorkCellByWorkCellCodes(workCellCodes));
    }
}
